﻿using Domain.User;
using Infratructure.Interface;
using MediatR;
using MES.Server.API.Application.Command.Account;
using MES.Server.API.Dto.Account;
using MES.Server.API.Dto.Department;
using ReturnValue;

namespace MES.Server.API.Application.Handler.Account
{
    public class RoleGetHandler:IRequestHandler<RoleGetCommand,ApiResult<List<RoleDTO>>>
    {
        private readonly IRepository<RoleModel> roleway;

        public RoleGetHandler(IRepository<RoleModel> roleway)
        {
            this.roleway = roleway;
        }

        /// <summary>
        /// 获取角色下拉
        /// </summary>
        /// <param name="request">无参</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>角色列表</returns>
        public Task<ApiResult<List<RoleDTO>>> Handle(RoleGetCommand request, CancellationToken cancellationToken)
        {
            var roles = roleway.GetAll().Where(x => !x.IsDel);
            var linq = from a in roles
                       select new RoleDTO()
                       {
                           Id = a.Id,
                            RoleName=a.RoleName
                         
                       };
            ApiResult<List<RoleDTO>>? res = new ApiResult<List<RoleDTO>>();
            res.Message = "查询成功";
            res.Data = linq.ToList();
            res.Code = StatusCode.Success;
            return Task.FromResult(res);
        }
    }
}
